<?php
namespace app\admin\controller;

use think\Controller;
use app\admin\model\Answer as Answers;
use think\Db;

class Answer extends Common
{
    private $cModel;   //当前控制器关联模型
    
    public function _initialize()
    {
        parent::_initialize();
        $this->cModel = new Answers;   //别名：避免与控制名冲突
    }

    public function delete(){
        if (request()->isPost()){
            $id = input('id');
            if (isset($id) && !empty($id)){
                Db::startTrans();
                try{
                    $result = $this->cModel->where('id='.$id)->delete();   //删除答案表数据
                    // 提交事务
                    if ($result){
                        Db::commit();
                        return ajaxReturn(lang('action_success'), url('Invest/index'));
                    }else{
                        return ajaxReturn($this->cModel->getError());
                    }
                } catch (\Exception $e) {
                    // 回滚事务
                    Db::rollback();
                    return ajaxReturn($e->getMessage());
                }
            }
        }

    }
}